<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script src="../js/vue.js"></script>
<!--父组件模板-->
<div id="app">
  <!--  父组件监听事件，不写（）参数，会将事件参数传递过来-->
  <cpn @itemclick="cpnClick"></cpn>
</div>
<!--子组件模板-->
<template id="cpn">
  <div>
    <button v-for="item in categories" @click="btnClick(item)">
      {{item.name}}
    </button>
  </div>
</template>

<script>
  const obj = {
    template: `#cpn`,
    data() {
      return {
        categories: [
          {id: 'aaa', name: '热门推荐'},
          {id: 'bbb', name: '手机数码'},
          {id: 'ccc', name: '家电家具'},
          {id: 'ddd', name: '电脑办公'},
        ]
      }
    },
    props: {},
    methods: {
      btnClick(item) {
        //子组件发射事件
        this.$emit('itemclick', item)
      }
    }
  }
  const app = new Vue({
    el: '#app',
    data: {
      message: "第一次，系统的学VUE"
    },
    components: {
      cpn: obj
    },
    methods: {
      cpnClick(item) {
        console.log(item)
      }
    }
  })
</script>
</body>
</html>